addpath([pwd,"/lib"]);
addpath([pwd,"/src"]);

load("rec.dat");
load("tstl.dat");

stats=[rec, tstl];

scores=[];
startTime = cputime;
confidenceLevel=0.44;
errors=[];
credibilityMatrix=[];

for(trial=1:size(rec,1))
	trainSet=stats(1:end!=trial,:);
	testSet=stats(trial,:);
	
	credibilityMatrix	= getPerformanceMatrix(trainSet);
	[testAnswers confidence] = maxCredibilityAnswer(testSet(:,1:end-1), credibilityMatrix,0.0078);
	testAnswers(confidence<confidenceLevel)=10;
    if(testAnswers(1,1)!=10 && testAnswers(1,1)!=testSet(1,6))
        errors=[errors;trial];
    end;
	scores=[scores; sum(testAnswers==testSet(:,6))/size(testSet,1), sum(testAnswers==10)/size(testSet,1)];
	if(mod(trial,250)==0)
		printf("ITERATION: %d, TIME ELAPSED: %d sec \n",trial,cputime-startTime);
		printf("Last-> score	: %f, discarded: %f \n",scores(size(scores,1),1),scores(size(scores,1),2));
		printf("Mean-> score : %f, discarded: %f, errors: %f \n",mean(scores(:,1)), ...
			mean(scores(:,2)), 1-mean(scores(:,1))-mean(scores(:,2)));
		fflush(stdout);
	end;
end;

printf("Average over %d iterations -> score: %f, discarded: %f \n", size(stats,1), mean(scores(:,1)), mean(scores(:,2)), ...
	1-mean(scores(:,1))-mean(scores(:,2)));


